package com.sky.websocket;

import org.springframework.stereotype.Component;

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.util.ArrayList;
import java.util.List;

@Component
@ServerEndpoint("/ws")
public class WebSocket {

    private List<Session> sessionList = new ArrayList<>();
    @OnOpen
    public void onOpen(Session session){
        System.out.println("有连接进来了~~~  " + session);
        sessionList.add(session);
    }

    @OnMessage
    public void onMessage(String message){
        System.out.println("有连接进来了~~~ 并且发送了消息 :  " + message);
    }

    @OnClose
    public void onClose(){
        System.out.println("有连接断开了~~~  ");
    }
}
